package com.charles.bigdata.mapreduce.phone;

import java.io.IOException;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class PhoneMapper extends Mapper<LongWritable, Text, Text, FlowBean> {

	@Override
	protected void map(LongWritable key1, Text value1, Context context) {

		// 数据： I like MapReduce
		String data = value1.toString();

		// 分词：按空格来分词
		String[] words = data.split("\t");

		String phone = words[0];
		long upFlow = Long.parseLong(words[1]);
		long dFlow = Long.parseLong(words[2]);
		long sumFlow = upFlow + dFlow;

		// 输出 k2    v2
		try {
			context.write(new Text(phone), new FlowBean(upFlow, dFlow, sumFlow));
		} catch (IOException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

}